/*************************************************************************
 * Copyright 2008 David Almilli
 *  
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 *  
 *     http://www.apache.org/licenses/LICENSE-2.0 
 *      
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and 
 * limitations under the License.
 **************************************************************************/
package com.tivo.hme.bananas;

import com.tivo.hme.sdk.Resource;

public class BDisabledHighlight extends BHighlightPlus {
	protected BView disabledView;
	protected String disabledName;

	public BDisabledHighlight(String name, Object action, int dx, int dy) {
		this(name, name + "-disabled", action, dx, dy);
	}

	public BDisabledHighlight(String name, String disabledName, Object action, int dx, int dy) {
		super(name, action, dx, dy);
		this.disabledName = disabledName;
	}

    public void refresh(BHighlights h, BScreen s, BRect r, Resource animation) {

        int x = r.x + dx;
        int y = r.y + dy;
        
    	if (!h.getLayout().getHighlightIsVisible(visible)) {
            if (disabledView == null) {
                // create the disabled view
                BSkin skin = s.getBApp().getSkin();
                BView parent = isAbove ? s.getAbove() : s.getBelow();

                // skin it (and maybe stretch it)
                if (width == -1) {
                	disabledView = skin.createSkin(parent, getDisabledName(), x, y);
                } else {
                	disabledView = skin.createSkinStretch(parent, getDisabledName(), x, y, width);
                }
            } else {
                // show the existing view
            	disabledView.setVisible(true);
            	disabledView.setLocation(x, y, animation);  
                if (width != -1 && width != disabledView.getWidth()) {
                	disabledView.setSize(width, disabledView.getHeight(), animation);
                }
            }
    	} else {
    		if (disabledView != null) {
                // hide it
    			disabledView.setVisible(false, animation);
    			disabledView.setLocation(x, y, animation);            
            }
    	}
		super.refresh(h, s, r, animation);
    }

	public String getDisabledName() {
		return disabledName;
	}

}
